package org.invigorare.auctions.widgets;

import java.util.Map;

import org.invigorare.auctions.R;
import org.invigorare.auctions.data.ProduceDataOpener;
import org.invigorare.auctions.data.entities.EntryInfo;
import org.invigorare.auctions.data.entities.Licensee;
import org.invigorare.auctions.data.entities.Licensee.LicenseType;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

public class EntryDisplayHelper {

	
	static Map<Integer, String> produceTypes = null;
	
	public static void setEntryToDisplay(Context context, View v, EntryInfo entry) {
		
		if (produceTypes == null) {
			produceTypes = ProduceDataOpener.getProduceIds(context, context.getString(R.string.languageCode));
		}
		
		boolean entryExists = true;
		if (entry == null) {
			entry = new EntryInfo("", "", "", "", "", 0, 0, "", "", "");
			entryExists = false;
		}
		
    	TextView id = (TextView) v.findViewById(R.id.entry_id);
    	TextView dName = (TextView) v.findViewById(R.id.entry_driverName);
    	TextView vNo = (TextView) v.findViewById(R.id.entry_vehicleNo);
    	TextView vType = (TextView) v.findViewById(R.id.entry_vehicleType);
    	TextView prodName = (TextView) v.findViewById(R.id.entry_prodName);
    	TextView prodWeight = (TextView) v.findViewById(R.id.entry_prodWeight);
    	TextView prodFarm = (TextView) v.findViewById(R.id.entry_prodFarm);

	    setText(id, "(" + entry.entryId + ")");
	    setText(dName, entry.driverName);
	    setText(vNo, entry.vehNo);
	    setText(vType, "  (" + entry.vehType + ")");
	    setText(prodName, produceTypes.get(entry.prodId)); // map
	    setText(prodWeight, String.valueOf(entry.prodWeight));
	    setText(prodFarm, entry.prodFarm);
	}
	
	private static void setText(TextView t, String s) {
		if (t != null) {
			t.setText(s);
		}
	}

}
